package cn.yuhh.dao;

import cn.yuhh.entity.Blog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface BlogDao extends JpaRepository<Blog,Long>, JpaSpecificationExecutor<Blog> {

    @Query(value = "select * from Blog.t_blog where id in (select blogs_id from t_blog_tags where tags_id=?1)",
            nativeQuery = true)
    List<Blog> findBlogsByTag(Long tagId);

    List<Blog> findBlogsByType(long typeId);

    Optional<Blog> findById(Long id);
}
